package service

import (
	"sync"
	"test-gin/entity"
	"test-gin/utils"
)

type UserService struct {
}

var userService *UserService
var onceUserService sync.Once

func GetUserService() *UserService {
	onceUserService.Do(func() {
		userService = &UserService{}
	})
	return userService
}

func InitUserService() {
	// 用户相关服务
}

func (s *UserService) GetAllUsers() []entity.UserEntity {
	db, err := utils.GetDB()
	if err != nil {
		return nil
	}
	var users []entity.UserEntity
	result := db.Find(&users)
	if result.Error != nil {
		return nil
	}
	return users
}
